package cn.edu.fzu.homemaking.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
public class CommonConfig {

    public static final String EXCHANGE_TOPICS_EMAIL = "exchange_topics_email";

    public static final String QUEUE_EMAIL           = "queue_email";

    public static final String ROUTING_EMAIL         = "email.#";

    /** 声明交换机 **/
    @Bean(EXCHANGE_TOPICS_EMAIL)
    public Exchange EXCHANGE_TOPICS_EMAIL() {
        return ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_EMAIL).durable(true).build();
    }


    /** 声明队列 **/
    @Bean(QUEUE_EMAIL)
    public Queue QUEUE_EMAIL() {
        return new Queue(QUEUE_EMAIL);
    }


    @Bean
    public Binding BINDING_QUEUE_INFORM_EMAIL(@Qualifier(QUEUE_EMAIL) Queue queue,
                                              @Qualifier(EXCHANGE_TOPICS_EMAIL) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(ROUTING_EMAIL).noargs();
    }

}
